package com.lzxuni.modules.basics.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lzxuni.modules.basics.entity.BasicsLand;
import com.lzxuni.modules.common.entity.Tree;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * <p>
 * 基础信息_地块管理 Mapper 接口
 * </p>
 *
 * @author LaoNa
 * @since 2020-11-24
 */
public interface BasicsLandMapper extends BaseMapper<BasicsLand> {
        //查询列表信息
        List<BasicsLand> queryList(BasicsLand basicsLand);

        List<Tree> getParentTree(@Param("landId") String landId, @Param("parentId") String parentId);


        String queryLandIds(@Param("parentId") String parentId);

        String queryCount();
        /**
         *
         函数
         CREATE DEFINER=`root`@`%` FUNCTION `idsFun`(
         rootId VARCHAR ( 200 )) RETURNS varchar(5000) CHARSET utf8
         BEGIN
         DECLARE
         cid VARCHAR ( 10000 );
         DECLARE
         aid VARCHAR ( 10000 ) DEFAULT '';
         DECLARE
         lid VARCHAR ( 10000 ) DEFAULT '';
         DECLARE
         ids VARCHAR ( 10000 ) DEFAULT '';
         SET cid = rootId;

         -- 查询所有地区id
         WHILE
         cid IS NOT NULL DO
         SET aid = concat( aid, ',', cid );
         SELECT
         group_concat( area_id ) INTO cid
         FROM
         base_area
         WHERE
         FIND_IN_SET( parent_id, cid );

         END WHILE;
         -- 	select aid;
         -- 	查询一级地块
         SELECT
         IFNULL(group_concat( land_id ),"") INTO lid
         FROM
         tbl_basics_land
         WHERE
         (FIND_IN_SET( area_id, aid )
         or FIND_IN_SET( land_id, aid ) )
         AND parent_id = '-1';
         -- 查询二级地块
         --  	select lid;
         SELECT
         IFNULL(group_concat( land_id ),"") INTO ids
         FROM
         tbl_basics_land
         WHERE
         (FIND_IN_SET( parent_id, lid )
         or FIND_IN_SET( land_id, lid )
         or FIND_IN_SET( land_id, aid ) )
         AND parent_id != '-1';-- 	/RETURN ids;
         -- 		select ids;
         SET ids = concat( lid, ',', ids);
         RETURN ids;
         END

存储过程
         CREATE DEFINER=`root`@`%` PROCEDURE `queryIds`(
         rootId VARCHAR ( 200 ))
         BEGIN
         DECLARE
         cid VARCHAR ( 10000 );
         DECLARE
         aid VARCHAR ( 10000 ) DEFAULT '';
         DECLARE
         lid VARCHAR ( 10000 ) DEFAULT '';
         DECLARE
         ids VARCHAR ( 10000 ) DEFAULT '';
         SET cid = rootId;

         -- 查询所有地区id
         WHILE
         cid IS NOT NULL DO
         SET aid = concat( aid, ',', cid );
         SELECT
         group_concat( area_id ) INTO cid
         FROM
         base_area
         WHERE
         FIND_IN_SET( parent_id, cid );

         END WHILE;
         -- 	select aid;
         -- 	查询一级地块
         SELECT
         IFNULL(group_concat( land_id ),"") INTO lid
         FROM
         tbl_basics_land
         WHERE
         (FIND_IN_SET( area_id, aid )
         or FIND_IN_SET( land_id, aid ) )
         AND parent_id = '-1';
         -- 查询二级地块
         --  	select lid;
         SELECT
         IFNULL(group_concat( land_id ),"") INTO ids
         FROM
         tbl_basics_land
         WHERE
         (FIND_IN_SET( parent_id, lid )
         or FIND_IN_SET( land_id, lid )
         or FIND_IN_SET( land_id, aid ) )
         AND parent_id != '-1';-- 	/RETURN ids;
         -- 		select ids;
         SET ids = concat( lid, ',', ids);
         select ids;
         END

         */
}